<?php
/**
 * 异常拦截机制<p/>
 * @catepory 异常处理
 * @author zhouhaichao(a)2008.sina.com
 * @version 1.0 & 2013-2-21
 * @copyright (c) 2008
 */
if (function_exists('error_reporting')) {
    error_reporting(E_ALL | E_STRICT);
}
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
    $dt = date("Y-m-d H:i:s");
    $day = date("Ymd");
    $errortype = array(
        E_ERROR => "Error",
        E_WARNING => "Warning",
        E_PARSE => "Parsing Error",
        E_NOTICE => "Notice",
        E_CORE_ERROR => "Core Error",
        E_CORE_WARNING => "Core Warning",
        E_COMPILE_ERROR => "Compile Error",
        E_COMPILE_WARNING => "Compile Warning",
        E_USER_ERROR => "User Error",
        E_USER_WARNING => "User Warning",
        E_USER_NOTICE => "User Notice",
        E_STRICT => "Runtime Notice"
    );
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

    if (true) {
        $err = "";
        $err .= $errmsg . "<br/>";
        $err .= "At : " . $filename . " in line " . $linenum . "<br/>";
        if (in_array($errno, $user_errors) && $vars) {
            $err .= "With Param : <br/> " . wddx_serialize_value($vars, "Variables") . "<br/>";
        }
        $err .= ("At time : " . $dt);

        if (ob_get_level()) {
            ob_end_clean();
        }
        ob_start();
        $title = $errortype[$errno];
        $message = $err;
        require_once ROOT . '/system/error/error.php';
        $buffer = ob_get_contents();
        ob_end_clean();
        echo $buffer;
        exit;
    } else {
        $err = "";
        $err .= $errmsg . "\n";
        $err .= "At : " . $filename . " in line " . $linenum . "\n";
        if (in_array($errno, $user_errors) && $vars) {
            $err .= "With Param : \n " . wddx_serialize_value($vars, "Variables") . "\n";
        }
        $err .= ("At time : " . $dt);
        error_log($err);
    }
}
set_error_handler("userErrorHandler");